const http = require("http");
const Koa = require("koa");
const Router = require("koa-router");
const router = new Router();
const app = new Koa();
// const crateSlice = require('./slice')
const Worker = require("./worker");

const worker = new Worker();

router.get("/slice", (ctx) => {
  const query = ctx.query;
  //   console.log("query", query);
  worker.add(query);
});

app.use((ctx, next) => {
  // 设置允许跨域
  ctx.set("Access-Control-Allow-Origin", "*");
  ctx.set("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS");
  // 请求头设置
  ctx.set(
    "Access-Control-Allow-Headers",
    `Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild,x-token,sessionToken,token`
  );
  if (ctx.method == "OPTIONS") {
    ctx.body = 200;
  } else {
    next();
  }
});

app.use(router.routes());

app.listen(5000, () => {
  console.log("切片服务启动成功!!");
});
